package code20211109;

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

public class C488 {

	public static void main(String[] args) {
		findMinStep("DSFACAC", "GG");

	}
	public static void findMinStep(String board, String hand) {
		Map<Character, Integer> boardMap = new HashMap<>();
		for(int i=0;i<board.length();i++) {
			boardMap.put(board.charAt(i), boardMap.getOrDefault(board.charAt(i), 0)+1);
		}
		boardMap = sortMapByValues(boardMap);
		for (char c:boardMap.keySet()) {
			System.out.println(c+","+boardMap.get(c));
		}
		System.out.println();
    }
	private static Map<Character, Integer> sortMapByValues(Map<Character, Integer> aMap) { 
		 
        Set<Entry<Character, Integer>> mapEntries = aMap.entrySet(); 
        List<Entry<Character, Integer>> aList = new LinkedList<Entry<Character, Integer>>(mapEntries); 
        Collections.sort(aList, new Comparator<Entry<Character, Integer>>() { 
            @Override 
            public int compare(Entry<Character, Integer> ele1, 
                    Entry<Character, Integer> ele2) { 
                return ele2.getValue().compareTo(ele1.getValue()); 
            } 
        }); 
        Map<Character, Integer> aMap2 = new LinkedHashMap<Character, Integer>(); 
        for(Entry<Character, Integer> entry: aList) { 
            aMap2.put(entry.getKey(), entry.getValue()); 
        } 
        return aMap2;
 
    } 
}
